package com.twu.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by thoughtworks on 28/7/14.
 */
public class IOHandler {
    InputStreamReader inputStreamReader;
    BufferedReader bufferedReader;

    public void displayString(String string) {
        System.out.println(string);
    }

    public IOHandler() {
       inputStreamReader = new InputStreamReader(System.in);
        bufferedReader = new BufferedReader(inputStreamReader);
    }

    public int getInteger() {
        boolean flag = false;
        int returnValue = -1;

            while (flag == false) {
                try {
                    flag = true;
                    returnValue = Integer.parseInt(bufferedReader.readLine());

                } catch (Exception e) {
                    flag = false;
                    displayString("IO Error : " + e.getMessage());
                }
            }

        return returnValue;
    }
    public String getString(){
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        try {
            return (bufferedReader.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
